package com.xspace.android.xafcommon.network.task;
/**
 * @ClassName: TaskManager
 * @author:qbluo
 * @Date�?012-8-23
 * @version  V1.0.0
 * @Description: 网络连连接池管理
 */
public class TaskManager 
{
    private static final String TAG = "TaskManager";
    private static TaskManager instance = TaskManager.getInstance();
    
    private ThreadPool mTouchThreadPool;
    /**
     * @Description: 单例模式
     *  @return TaskManager
     */
    public static TaskManager getInstance() 
    {
        if (instance == null) 
        {
            instance = new TaskManager();
        }
        return instance;
    }
    /**
     * @Description: 初始化线程池，支�?个并发连�?
     */
    public void init()
    {
        mTouchThreadPool = new ThreadPool(5);
    }
    /**
     * @Description: 添加任务
     *  @param newTask void
     */
    public void addTask(ITask newTask) 
    {
    	if(mTouchThreadPool == null){
    		init();
    	}
        if (null == newTask){return;}
        mTouchThreadPool.addTask(newTask);
    }
    
    /**
     * @Description: 取消任务
     *  @param serId void
     */
    public void cancelTask(int serId)
    {
    	if(mTouchThreadPool==null){
    		return;
    	}
        mTouchThreadPool.cancelTask(serId);
    }
    /**
     * @Description: 注销网络连接�?
     */
    public void destroy()
    {
        if (null != mTouchThreadPool)
        {
            mTouchThreadPool.destroy();
            mTouchThreadPool = null;
        }
    }
}
